/**
 * @param {Array} arr
 */
function sort(arr, l, r) {
  if (l >= r) {
    return;
  }
  let temp = arr[l];
  let x = l;
  let y = r;
  while (l < r) {
    while (l < r && arr[r] > temp) {
      r--;
    }
    arr[l] = arr[r];
    while (l < r && arr[l] < temp) {
      l++;
    }
    arr[r] = arr[l];
  }
  arr[l] = temp;
  sort(arr, x, l - 1);
  sort(arr, l + 1, y);
}

let arr = [4, 6, 7, 3, 2, 1];

sort(arr, 0, 5);

console.log(arr);
